package com.briup.smartcity_group7.web.controller;

import com.briup.smartcity_group7.bean.basic.Article;
import com.briup.smartcity_group7.bean.ext.ArticleExt;
import com.briup.smartcity_group7.service.IArticleService;
import com.briup.smartcity_group7.util.Result;
import com.briup.smartcity_group7.util.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "资讯信息模块")
@RequestMapping("/auth/article")
public class ArticleController {
    @Autowired
    private IArticleService service;

    @PutMapping("/changeStatus")
    public Result changeStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) {
        service.changeStatus(id, status);
        return ResultUtil.success("修改咨询成功");
    }

    @GetMapping
    public Result findById(Integer id){
        ArticleExt articleExt = service.findByIdWithCategoryAndUser(id);
        return ResultUtil.success(articleExt);
    }

    @PostMapping
    public Result saveOrUpdate(Article article){
        service.saveOrUpdate(article);
        return ResultUtil.success("保存/更新成功");
    }

    @GetMapping("/page/categoryAndUser")
    public Result findBySelectivePage(Integer pageNum,Integer pageSize,String title,Integer status,Integer categoryId){
        PageInfo<ArticleExt> pageInfo = service.pageQueryArticleWithCategoryAndUser(pageNum, pageSize,title,status,categoryId);
        return ResultUtil.success(pageInfo);
    }

    @DeleteMapping
    public Result deleteById(Integer id){
        service.deleteById(id);
        return ResultUtil.success("删除成功");
    }

    @GetMapping("/page/query/recommend")
    public Result findByPage(Integer pageNum,Integer pageSize){
        PageInfo<ArticleExt> pageInfo = service.pageQueryRecommend(pageNum, pageSize);
        return ResultUtil.success(pageInfo);
    }


}
